package com.service;

import com.dao.userdao.Login;
import com.pojo.User;
import com.util.MD5Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理登录界面的请求
 */
public class LoginService {

    /**
     *用户登录
     */
    public static boolean login_check(String username,String password) throws IOException {
            boolean resp=true;
            User user=new User();
            String is_mailbox="^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
            if(username.matches(is_mailbox))
            {
                user.setMailbox(username);
            }else{
                user.setUsername(username);
            }
            MD5Util md=new MD5Util();
            user.setPassword(md.digest(password));
            resp=Login.login_check(user);
            return resp;
    }

    /**
     * 管理员登录
     */
    public static boolean manager_login(HttpServletRequest req)throws IOException{
             String username=req.getParameter("username");
             String pwd=req.getParameter("password");
             return Login.manager_login(username,pwd);
    }
}
